package dnd;

import java.awt.Color;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.LayoutManager;

import java.awt.event.KeyEvent;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;
import javax.swing.JButton;

@SuppressWarnings("serial")
public class DNDGui extends JFrame {
	Character c = null;
	public DNDGui() {
		initGui();

		initButtonPanel();

	}
	
	//Create the basic GUI, Menu
	//Also contains code for newCharacter menu item
	public void initGui() {
		JMenuBar menubar = new JMenuBar();
		
		JMenu file = new JMenu("File");
		file.setMnemonic(KeyEvent.VK_F);
		
		JMenuItem newCharacter = new JMenuItem("New Character");
		newCharacter.setMnemonic(KeyEvent.VK_N);
		newCharacter.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				setBackground(Color.BLACK);
				add(c = new Character());
				c.setVisible(true);
				reset();
			}
		});
		
		JMenuItem load = new JMenuItem("Load Character");
		load.setMnemonic(KeyEvent.VK_L);
		
		JMenuItem save = new JMenuItem("Save Character");
		save.setMnemonic(KeyEvent.VK_S);
		
		JMenuItem exit = new JMenuItem("Exit");
		exit.setMnemonic(KeyEvent.VK_X);
		exit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			}
		});
		exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK));
		
		file.add(newCharacter);
		file.addSeparator();
		file.add(load);
		file.add(save);
		file.addSeparator();
		file.add(exit);
		menubar.add(file);
		
		setTitle("Character Sheet");
		setJMenuBar(menubar);
		setSize(400,500);
		setResizable(false);
		setLocationRelativeTo(null);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setVisible(true);
	}
	
	//Adds buttons and listeners to the bottom of the frame
	public void initButtonPanel() {
		JPanel buttonPanel = new JPanel((LayoutManager) new FlowLayout(FlowLayout.RIGHT));
		
		JButton submitButton = new JButton("Submit");
		submitButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(c != null)
					//submit();
					;
			}
		});
		
		JButton resetButton = new JButton("Reset");
		resetButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				reset();
			}
		});
		
		buttonPanel.setBackground(Color.WHITE);
		buttonPanel.add(submitButton);
		buttonPanel.add(resetButton);
		
		
		add(BorderLayout.SOUTH, buttonPanel);
	}
	
	//Resets all data, either when the reset button is clicked, or when a new character is created
	public void reset() {
		if(c != null)
			c.reset();
	}

/**------------------------------------------------
 * 
 * need to figure this out
	//Displays input data in a finalized table
	public void submit() {
		JPanel submitPanel = new JPanel();
		
		JLabel name = new JLabel("Name");
		JButton button = new JButton("Button");
		
		submitPanel.add(name);
		submitPanel.add(button);
		
		add(BorderLayout.EAST, submitPanel);
	}
-------------------------------------------------*/	
	public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				new DNDGui();
			}
		});
	}
		
}
